<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>

</head>
<body>
<div th:fragment="alarm-pop-div">

    <div class="alarm-pop-div alarm-pop-div-style alertWarningContent">
        <div class="alarm-pop-header">
            <div class="header-notice header-notice-style">报警信息 : <span></span> 条</div>
            <!-- -------注释-------- -->
            <!-- <div class="close-btn"></div>  -->

        
        </div>
        <div class="alarm-pop-body-style alarm-pop-body">
            <div class="smoke-alarm-pop-box">
                <!-- TODO -->
                <!-- <div class="smokeActiveContent active-content-style none"><div class="alarm-title">报警！！！</div><div class="alarm-content-body"><div class="time-box"><div class="alarm-time"><div class="startTime">dates</div><div class="w">WARNING</div><div class="endTime">seconds</div></div></div><div class="alarm-con"><div class="alarm-row"><label>地址：</label><div class="alarm-address-box"><div class="con-right alarm-address">address</div></div></div><div class="alarm-row "><label>联系人：</label><div class="con-right"><div><span>linkman1</span><span>linkPhone1</span><span>linkman2</span><span>linkPhone2</span></div><div>'<span>linkman3</span><span>linkPhone3</span><span>linkman4</span><span>linkPhone4</span></div></div></div><div class="alarm-content-footer"><button class="warningHandle">处理</button><button class="warningIgnore">忽略</button></div></div></div></div>
             --></div>
            <!-- 报警框侧边栏 -->
            <div class="alarm-list alertWarningInfo">
                <div class="top-arrow-btn nextPage"></div>
                <div class="list">
                    <!-- TODO -->
                </div>
                <div class="bottom-arrow-btn previousPage"></div>
            </div>
            


        
                       <!--  确认全部处理弹出框 -->
<!--         <div class="warningConfirmAll">
            <span class="closeConfirmAll"></span>
            <p class="WhetherAll">是否处理全部？</p>
            <button class="handleAll">是</button>
            <button class="denyAll">否</button>
        </div>  -->
        
        </div>

    </div>
                   <!--                 确认单个处理弹出框-->
     <div class="modal fade in" id="smoke-alarm-modal">
        <div class="smoke-warningConfirm warningConfirm">
        	<span class="closeConfirm"></span>
        	<p class="Whether">是否忽略全部？</p>
        	<button class="handle">是</button>
       	 	<button class="deny">否</button>
    	</div> 
	</div>
	
	<div class="modal fade in" id="waringCause-modal">
        <div class="waringCause warningConfirm">
        	<span class="closeConfirm"></span>
        	<p class="Whether">请输入报警原因</p>
      	      <select class="form-control" name="waringCause" style="width: 100px;">
                      <option th:attr="value=火警" selected>火警</option>
                      <option th:attr="value=粉尘">粉尘</option>
                      <option th:attr="value=炊烟">炊烟</option>
                      <option th:attr="value=吸烟">吸烟</option>
                      <option class="else" th:attr="value=其他">其他</option>
			  </select>
			  <textarea class="none" draggable="false"></textarea>
        	<button class="sure">确定</button>
       	 	<button class="cancal">取消</button>
    	</div> 
	</div>
	
    <script type="text/javascript">

        $(window).resize(function () {
            $(".alarm-pop-div").css({
                position: "absolute",
                left: ($(window).width() - $(".alarm-pop-div").outerWidth()) / 2,
                top: ($(window).height() - $(".alarm-pop-div").outerHeight()) / 2
            });
        });
        var maxWarningSum;
        var maxWarningNum = 0;
        
        var LiHeight = 198;
        var moveNum;
        var moveHeight;
        var page = 0;
        var warningIndex = 0;
        //实时添加
        function warningClear() {
            $(".alarm-pop-body .smoke-alarm-pop-box").html("");
        }
        for (var i = 1; i <= maxWarningSum; i++) {
            (function (arg) {
                $(".alertWarningInfo .list-item span").text(i);
            })(i);
        }

        //烟感火警报警—— 页面初始化渲染未处理 数据，报警弹出框/alarm/data/notdispose/smoke/byuser
        function alertWarningInit() {
            $.ajax({
                url: "/alarm/data/notdispose/smoke/byuser",
                type: "GET",
                async: false,
                success: function (result) {
                    if (result.status == "200") {
                        maxWarningSum = result.data.length;
                        
                        $(".header-notice span").text(maxWarningSum);
                        //大数据中的未处理数
                        $(".dataHandleNum").text(maxWarningSum)
                        $(".dataHandleNum1").text(maxWarningSum)
                      //设备切换按钮显示的数字
                        $("#smokeDetectorBtn .tip-alarm").text(maxWarningSum);
                        for (var i = 0; i < result.data.length; i++) {
                            var data = result.data[i];
                            var address = data.device.address;
                            var linkMan1 = data.device.linkMain1 ? data.device.linkMain1 : "";
                            var linkMan2 = data.device.linkMain2 ? data.device.linkMain2 : "";
                            var linkMan3 = data.device.linkMain3 ? data.device.linkMain3 : "";
                            var linkMan4 = data.device.linkMain4 ? data.device.linkMain4 : "";
                            var linkPhone1 = data.device.linkPhone1 ? data.device.linkPhone1 : "";
                            var linkPhone2 = data.device.linkPhone2 ? data.device.linkPhone2 : "";
                            var linkPhone3 = data.device.linkPhone3 ? data.device.linkPhone3 : "";
                            var linkPhone4 = data.device.linkPhone4 ? data.device.linkPhone4 : "";
                            var devCode = data.device.devCode;
                            var deviceName = data.device.deviceName;
                            var time = data.beginTime;
                            var alarmId = data.alarmId;
                            setAlertWarningInfo(deviceName, address, linkMan1, linkMan2, linkMan3, linkMan4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time);
							
                        }
                    } else {
                    	winTip.alert(result.message);
                    }
                }
            });
            //如果没有获取到数据，隐藏报警框
            if (!maxWarningSum) {
                $(".alertWarningContent").hide();
                stopSound();
            } else {
                $(".alertWarningContent").show();
                alertWarning();
            }
        };
        //烟感—— 报警实时添加
        function alertWarningInitTime(deviceName, address, linkMan1, linkMan2, linkMan3, linkMan4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time) {
            maxWarningSum++;
            $(".header-notice span").text(maxWarningSum);
            //大数据中的未处理数
            $(".dataHandleNum").text(maxWarningSum);
            $(".dataHandleNum1").text(maxWarningSum)
            $("#smokeDetectorBtn .tip-alarm").text(maxWarningSum);
            
            alertWarning();
            $(".alertWarningContent").show();
            setAlertWarningInfo(deviceName, address, linkMan1, linkMan2, linkMan3, linkMan4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time);
        }
        
//        设置报警框内容
        function setAlertWarningInfo(deviceName, address, linkman1, linkman2, linkman3, linkman4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time) {

            maxWarningNum++;
            //报警框右侧内容
            $(".alertWarningInfo .list").append('<div class="list-item"><span>' + maxWarningNum + '</span>. 烟感报警</div>');//<img src="/icons/smoke.svg" />
            //报警框左侧内容
            var dates = moment(time).format('YYYY-MM-DD');
            var seconds = moment(time).format('HH:mm:ss');
             $(".alarm-pop-body .smoke-alarm-pop-box").append('<div class="smokeActiveContent active-content-style none">' +
                    '<div class="alarm-title">报警！！！</div>' +
                    '<div class="alarm-content-body">' +
                    '<div class="time-box">' +
                    '<div class="alarm-time">' +
                    '<div class="startTime">' + dates + '</div>' +
                    '<div class="w">WARNING</div>' +
                    '<div class="endTime">' + seconds + '</div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="alarm-con">' +
                    '<div class="alarm-row">' +
                    '<label>地址：</label>' +
                    '<div class="alarm-address-box">' +
                    '<div class="con-right alarm-address">' + address + '</div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="alarm-row ">' +
                    '<label>联系人：</label>' +
                    '<div class="con-right">' +
                    '<div>' +
                    '<span>' + linkman1 + ' </span>' +
                    '<span>' + linkPhone1 + '</span>' +
                    '<span>' + linkman2 + ' </span>' +
                    '<span>' + linkPhone2 + '</span>' +
                    '</div>' +
                    '<div>' +
                    '<span>' + linkman3 + ' </span>' +
                    '<span>' + linkPhone3 + '</span>' +
                    '<span>' + linkman4 + ' </span>' +
                    '<span>' + linkPhone4 + '</span>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="alarm-content-footer" devCode='+devCode+' alarmId=' + alarmId + '>' +
                    '<button class="warningHandle">处理</button>' +
                    '<button class="warningIgnore">忽略</button>' +
                    '</div>' +
                    '</div>' +

                    '</div>' +
                    '</div>'); 
                    /* $(".startTime").text(dates);
                    $(".endTime").text(seconds);
                    $(".alarm-address").text(address);
                    $(".con-right").html('<div><span>' + linkman1 + ' </span><span>' + linkPhone1 + '</span><span>' + linkman2 + ' </span><span>' + linkPhone2 + '</span></div><div>'<span>' + linkman3 + ' </span><span>' + linkPhone3 + '</span><span>' + linkman4 + ' </span><span>' + linkPhone4 + '</span></div>');
                    $(".alarm-content-footer").attr("alarmId",alarmId); */

            //页面初始化显示第一条火警信息
            $(".alertWarningInfo .list .list-item").eq(0).addClass("active").siblings().removeClass("active");
            $('.smokeActiveContent').eq(0).removeClass('none').siblings().addClass("none");
        };
        //报警处理时，不同客户端同步处理
        function warningSync(alarmId) {
            $(".alarm-content-footer").each(function () {
                if ($(this).attr("alarmId") == alarmId) {
                    $('.alarm-pop-body .list-item').eq(warningIndex).remove();
                    //右侧部分
                    $(".alarm-pop-body .list-item").eq(warningIndex).addClass('active').siblings().removeClass('active');
                    //左侧内容切换
                    $('.smokeActiveContent').eq(warningIndex).removeClass('none').siblings().addClass('none');

                    if (warningIndex == maxWarningSum - 1)
                        warningIndex--;
//                  右侧
                    $(".alarm-pop-body .list-item").eq(warningIndex).addClass('active').siblings().removeClass('active');
                    //左侧容切换
                    $("[alarmId=" + alarmId + "]").parents(".smokeActiveContent").remove();
                    $('.smokeActiveContent').eq(warningIndex).removeClass('none').siblings().addClass('none');
                    //报警总数量更新
                    maxWarningSum--;
                    maxWarningNum--;
                    $(".header-notice span").text(maxWarningSum);
                    //大数据中的未处理数
                    $(".dataHandleNum").text(maxWarningSum)
                    $(".dataHandleNum1").text(maxWarningSum)
                    $("#smokeDetectorBtn .tip-alarm").text(maxWarningSum);
					//如果设备切换按钮有数字则显示，否则隐藏
                    smokeTipAlarmFunc();
                    if (maxWarningSum <= 0) {
                    	//关闭火警报警框
                        $(".alertWarningContent").hide();
                        stopSound();
                    }
                    
                    warningNum();
                }
            })
        }

        function alertWarning() {

            $(".alarm-pop-div").css({
                position: "absolute",
                left: ($(window).width() - $(".alarm-pop-div").outerWidth()) / 2,
                top: ($(window).height() - $(".alarm-pop-div").outerHeight()) / 2
            });

            $(".alarm-pop-div").show();
            //报警tab栏头部切换功能
            $('.alarm-pop-body').on("click", ".alertWarningInfo .list .list-item", function () {
                warningIndex = $(this).index();
//                    右侧部分
                $(this).addClass('active').siblings().removeClass('active');
//                    左侧内容切换
                $('.smokeActiveContent').eq(warningIndex).removeClass('none').siblings().addClass('none');
                return false;
            });
            //处理状态：1->处理，2->忽略
            var disposeStatusUrl = null;
            //点击处理,弹出填写报警原因框
            var warningHandleThis;
            $(".smoke-alarm-pop-box").off().on("click", ".alarm-content-footer .warningHandle", function () {
            	//------TODO-----------
            	//$("#waringCause-modal").show();
             	warningHandleThis = $(this);
             	var $this = $(this);
            	var waringCause = $("#waringCause-modal select").val();
            	waringCause = '';
            	waringCause = "&alarmReasons"+waringCause;
            	console.log(waringCause);
            	disposeStatusUrl = 1;
            	handleAlarmFunc($this,disposeStatusUrl,waringCause);  
            });

            //点击处理,删除内容和选择的按钮------------TODO------------
            $("#waringCause-modal .sure").on("click",function (){
            	var waringCause = $("#waringCause-modal select").val();
            	var waringCauseArea = $("#waringCause-modal textarea").val();
            	console.log(!!waringCauseArea)
            	if(waringCauseArea){
            		waringCause = "&alarmReasons="+waringCause+"&remark="+waringCauseArea;
            	}else{
            		waringCause = "&alarmReasons="+waringCause;
            	}
            	
            	console.log(waringCause);
            	disposeStatusUrl = 1;
            	handleAlarmFunc(warningHandleThis,disposeStatusUrl,waringCause);
            }); 
            $("#waringCause-modal select").on("click",function (){
            	console.log($(this).val())
            	if($(this).val()=='其他'){
            		$("#waringCause-modal textarea").show();
            	}else{
            		$("#waringCause-modal textarea").hide();
            	}
            });
            //点击报警原因的取消按钮
            $("#waringCause-modal .sure").on("click",function (){
            	$("#waringCause-modal").hide();
            	waringCauseHide();
            });
            //点击忽略,删除内容和选择的按钮
            $(".smoke-alarm-pop-box").on("click", ".alarm-content-footer .warningIgnore", function () {
            	var $this = $(this);
            	disposeStatusUrl = 2;
            	var waringCause = '';
            	handleAlarmFunc($this,disposeStatusUrl,waringCause);
            });
            // 隐藏报警原因框并清空内容
            function waringCauseHide(){
            	$("#waringCause-modal").hide();
            	$("#waringCause-modal select").eq(0).attr("selected","true");
            	$("#waringCause-modal textarea").val('');
            }
            
            //处理和忽略的公共逻辑部分 
            function handleAlarmFunc($this,disposeStatusUrl,waringCause) {
                var alarmId = $this.parent().attr("alarmId");
                var devCode = $this.parent().attr("devCode");
                $.ajax({
                    url: "/alarm/data/disposealarm",
                    type: "POST",
                    data: "devCode="+devCode+"&alarmId=" + alarmId + "&disposeStatus=" +disposeStatusUrl+waringCause,
                    async:false,
                    success: function (result) {
                        if (result.status == "200") {

                            $this.parents(".smokeActiveContent").remove();
                            $('.alarm-pop-body .list-item').eq(warningIndex).remove();
                            
                            if (warningIndex == maxWarningSum - 1)
                                warningIndex--;
//                          右侧
                            $(".alarm-pop-body .list-item").eq(warningIndex).addClass('active').siblings().removeClass('active');
//                          左侧容切换
                            $('.smokeActiveContent').eq(warningIndex).removeClass('none').siblings().addClass('none');
                            //报警总数量更新
                            maxWarningSum--;
                            maxWarningNum--;
                            $(".header-notice span").text(maxWarningSum);
                            //大数据中的未处理数
                            $(".dataHandleNum").text(maxWarningSum)
                            $(".dataHandleNum1").text(maxWarningSum)
                            
                            $("#smokeDetectorBtn .tip-alarm").text(maxWarningSum);
                            smokeTipAlarmFunc();
                            if (maxWarningSum <= 0) {
                                $(".alertWarningContent").hide();
                                stopSound();
                            }
                            //如果是最后一页，处理完当前页数报警后翻到上一页
                            if (!(maxWarningNum % 6)) {
                                page--;
                                if (page <= 0) {
                                    page = 0;
                                }
                                moveNum = parseInt(maxWarningSum / 6);
                                if (page <= moveNum && page >= 0) {
                                    moveHeight = LiHeight * page;
                                    $(".alarm-pop-body .list-item").eq(0).animate({marginTop: -moveHeight + "px"}, 0);
                                }
                            }
                            waringCauseHide();
                        } else {
                        	winTip.alert(result.message);
                        }
                    }
                });
                warningNum();
            }

            //翻页

            //页数初始化
            //$(".previousPage").text(page+1);
            $(".alarm-pop-body").on("click", ".previousPage", function () {
                //点击按钮下一页
                page++;
                moveNum = parseInt(maxWarningSum / 6);
                if (page >maxWarningSum / 6) {
                    page = moveNum;
                }else if(page == (maxWarningSum / 6)){
                	page = moveNum-1;
                }
                if (page <= moveNum && page >= 0) {
                    moveHeight = LiHeight * page;
                    $(".alarm-pop-body .list-item").eq(0).animate({marginTop: -moveHeight + "px"}, 0);
                }
            });
            $(".alarm-pop-body").on("click", ".nextPage", function () {
                //点击按钮上一页
                page--;
                if (page <= 0) {
                    page = 0;
                }
                moveNum = parseInt(maxWarningSum / 6);
                if (page <= moveNum && page >= 0) {
                    moveHeight = LiHeight * page;
                    $(".alarm-pop-body .list-item").eq(0).animate({marginTop: -moveHeight + "px"}, 0);
                }else if(page == (maxWarningSum / 6)){
                	page = moveNum-1;
                }
                //$(".previousPage").text(page+1);
            });
        }
        //报警框右侧报警栏序号处理
/*         function warningNum() {以前的，速度慢
            for (var i = 1; i <= maxWarningSum; i++) {
                (function () {
                    $(".alertWarningInfo .list .list-item span").each(function (index, item) {
                        $(this).text(index + 1);
                    });
                })(i);
            }
        } */
        //改版，速度快 
        function warningNum() {
            for (var i = 1; i <= maxWarningSum; i++) {
                $(".alertWarningInfo .list-item").eq(i-1).find("span").text(i);
            }
        }
        $(".alertWarningContent .close-btn").on("click",function (){
        	$("#smoke-alarm-modal").show();
        	$(".smoke-warningConfirm").show();
        });
        var smokeHandleFlag = true;
        // 点击处理所有报警信息
        $(".smoke-warningConfirm").on("click",".handle",function (){
        	if(smokeHandleFlag){
        		smokeHandleFlag=false;
            	$(".alertWarningContent").hide();
            	$(".alarm-pop-body .smoke-alarm-pop-box").html('');
            	$(".alertWarningInfo .list").html('');
            	$(".smoke-warningConfirm").hide();
            	$("#smoke-alarm-modal").hide();
            	maxWarningNum=0;
            	alertWarningInit();
				console.log(999)
				smokeHandleFlag=true;
            	//删除数据后重新渲染报警信息 
               /*  $.ajax({
                    url: "/alarm/data/disposealarmall",
                    type: "POST",
                    data: "alarmId=" + alarmId + "&disposeStatus=2",//设备类型
                    success: function (result) {
                        if (result.status == "200") {
                        	$(".alertWarningContent").hide();
                        	$(".alarm-pop-body .smoke-alarm-pop-box").html('');
                        	$(".alertWarningInfo .list").html('');
                        	smokeHandleFlag=true;
                        } else {
                        	winTip.alert(result.message);
                        }
                    }
                }); */
        	}
        	
        });
        $(".smoke-warningConfirm").on("click",".deny",function (){
        	$(".smoke-warningConfirm").hide();
        	$("#smoke-alarm-modal").hide();
        });
        $(".smoke-warningConfirm").on("click",".closeConfirm",function (){
        	$(".smoke-warningConfirm").hide();
        	$("#smoke-alarm-modal").hide();
        });
        
    </script>


</div>
</body>
</html>